<% if card.image.attached? %>
  <%= button_to card_image_path(card), method: :delete, class: "btn", data: { controller: "tooltip" } do %>
    <%= icon_tag "picture-remove" %>
    <span class="for-screen-reader">Remove background image</span>
  <% end %>
<% elsif !card.closed? %>
  <%= form_with model: card, data: { controller: "form" } do |form| %>
    <label class="card-perma__image-btn btn input--file" data-controller="tooltip">
      <%= icon_tag "picture-add" %>
      <span class="for-screen-reader">Add background image</span>

      <%= form.file_field :image, class: "input",
            accept: "image/png, image/jpeg, image/jpg, image/webp",
            aria: { label: "Add background image" },
            data: { action: "upload-preview#previewImage form#submit", upload_preview_target: "input" } %>
    </label>
  <% end %>
<% end %>
